package org.wanda.pv.util;

import org.nutz.http.*;

import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;

public class MyHttp extends Http{

    public static Response post2(String url, Map<String, Object> params, Header header, int timeout) {
        return Sender.create(Request.create(url, Request.METHOD.POST, params, header)).setTimeout(timeout).setConnTimeout(Sender.Default_Conn_Timeout).send();
    }


    public static Response postData(String url, String params, Header header, int timeout) {
        Map<String, String> map = new HashMap<>();
        map.put("Content-Type", "application/json; charset=UTF-8");
        Header jsonHeader = Header.create(map);

        return Sender.create(Request.create(url,Request.METHOD.POST).setData(params).setHeader(header).setHeader(jsonHeader)).setTimeout(timeout).setConnTimeout(Sender.Default_Conn_Timeout).send();

    }

    public static Response get(String url,Map<String, Object> params, Header header, int timeout) {
        return Sender.create(Request.get(url).setParams(params).setHeader(header)).setTimeout(timeout).setConnTimeout(Sender.Default_Conn_Timeout).send();
    }


    public static String getMyIPLocal(){
        try{
            InetAddress ia = InetAddress.getLocalHost();
            return ia.getHostAddress();
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }

    }





}
